package web_vg.implementation.hl_services.main_service;

import tzhomestudio.framework.implementation.main_service.FrameworkMainService;
import tzhomestudio.framework.shared.utils.FileUtils;
import vg_connector.implementation.ClientAPIService;
import vg_connector.interfaces.IClientAPIService;
import web_vg.implementation.hl_services.gui_service.GUIService;
import web_vg.interfaces.hl_services.gui_service.IGUIService;

/**
 * This class contains links to all services.
 *
 * @author Timur Zolotuhin (e-mail: tzolotuhin@gmail.com)
 */
public class WVGMainService extends FrameworkMainService {
    // Main data
    protected static IGUIService guiService;
    protected static IClientAPIService clientAPIService;

    public static void executeInitialPreparations(String[] args) {
        synchronized (generalMutex) {
            try {
                // setup working dir for applet
                FileUtils.setWorkingDir(FileUtils.getUserHomeDir() + "wvg");

                FrameworkMainService.executeInitialPreparations();

                // add options
                cmdLine.addOption(WVGMainServiceHelper.CmdLineOptions.appInstanceIdOption);

                cmdLine.parseCmdLineArgs(args);

                guiService = new GUIService();
                clientAPIService = new ClientAPIService();

                // update helper
                updateHelper();
            } catch (Throwable ex) {
                throw new RuntimeException(ex);
            }
        }
    }

    public static void updateHelper() {
        synchronized (generalMutex) {
            FrameworkMainService.updateHelper();

            WVGMainServiceHelper.guiService = guiService;
            WVGMainServiceHelper.clientAPIService = clientAPIService;
        }
    }
}
